﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using EZMemoLib;

namespace Remember.WPF.Views
{
    /// <summary>
    /// Interaction logic for LoginAdd.xaml
    /// </summary>
    public partial class LoginAdd : UserControl
    {
        public event EventHandler OnClose;
        public event EventHandler OnRefresh;

        public LoginAdd()
        {
            InitializeComponent();
        }

        string  Save()
        {
            string loginID = null;
            string loginName = this.uiLoginName.Text.Trim();
            if (!string.IsNullOrEmpty(loginName) && loginName.Length >= 4)
            {
                if (this.uiPassword1.Password == this.uiPassword2.Password)
                {
                    loginID = Context.CreateLogin(this.uiLoginName.Text.Trim(), this.uiPassword1.Password);
                }
            }

            return loginID;
        }


        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            string loginID = Save();

            if (OnClose != null)
            {
                OnClose( loginID, e);
            }

            if (OnRefresh != null)
            {
                OnRefresh(loginID, e);
            }
        }

        private void btnCancel_Click(object sender, RoutedEventArgs e)
        {
            if (OnClose != null)
            {
                OnClose(this, e);
            }
        }
    }
}
